is_subclass_of
Checks whether the object takes this class as one of its parent classes or implements it: if this object is a subclass of the class, returns true
Function name: is_subclass_of()
Applicable version: PHP 4, PHP 5, PHP 7
Function description: The is_subclass_of() function is used to check whether an object is a subclass of the specified class.
Syntax: bool is_subclass_of ( mixed $object , string $class_name [, bool $allow_string = TRUE ] )
parameter:
Return value: Return TRUE if $object is a subclass or implementation class of $class_name, otherwise FALSE.
Example:
class ParentClass { } class ChildClass extends ParentClass { } $object = new ChildClass(); // 检查$object 是否是ParentClass 的子类if (is_subclass_of($object, 'ParentClass')) { echo 'ChildClass 是ParentClass 的子类'; } else { echo 'ChildClass 不是ParentClass 的子类'; }
Output:
ChildClass 是ParentClass 的子类
Notice: